<!--
 * @Description: 发现页面
 * @Author: Kerwin
 * @Date: 2024-08-27 10:34:18
 * @LastEditTime: 2025-05-23 13:48:46
 * @LastEditors:  Please set LastEditors
-->
<template>
    <view class="discover">
        <view class="cellBox" v-for="(itemGroup, index) in features" :key="index">
            <view class="gname" v-if="itemGroup.groupName"> {{ itemGroup.groupName }}</view>
            <view class="cellItem" v-for="(item, index2) in itemGroup.items" :key="index2" @click="handleClick(item)">
                <view class="cell-left">
                    <view class="icon">
                        <hy-svg :name="item.icon" :width="item.width || '40rpx'"></hy-svg>
                    </view>
                    <view class="con">
                        <view class="name"> {{ item.name }}</view>
                    </view>
                </view>
                <view class="cell-right">
                    <u-icon name="arrow-right" size="26" color="#B0B0B0"></u-icon>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts" setup>
import { useUserStore } from '@/store';
import { storeToRefs } from 'pinia'
import { ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app'
import { route } from '../../../utils/common';
//api
import { productApi } from '@/api'
//工具
import { getImgFullPath } from '@/utils';
//图片
import ic_qrcode from '@/static/ic_qrcode.png'
import icon_quanzi from '../../static/img/t01.png'
import icon_scan from '../../static/img/t02.png'
import icon_shake from '../../static/img/t12.png'
import icon_nearby from '../../static/img/t15.png'
import icon_app from '../../static/img/t18.png'

const userStore = useUserStore();
const { userInfo, myShopList } = storeToRefs(userStore)
const shopList = ref([])
const scanCode = () => {
    // @ts-ignore
    jWeixin.scanQRCode({
        needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
        desc: 'scanQRCode desc',
        success: function (res: { resultStr: any; }) {
            console.info('点击扫描按钮res...', res)
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
        },
        fail(err: any) {
            console.info('点击扫描按钮err...', err)
        }
    });

}
const features = ref([
    {
        groupName: '',
        items: [
            {
                name: '圈子',
                icon: 'icon-qz',
                path: '/packageD/pages/friendsCircle/index'
            }
        ],
    },
    {
        groupName: '',
        items:
            [
                // {
                //     name: '扫一扫',
                //     icon: icon_scan,
                //     path: '',
                //     handler: scanCode
                // },
                // {
                //     name: '摇一摇',
                //     icon: icon_shake,
                //     path: '/packageD/pages/shake/index'
                // },
                // {
                //     name: '附近',
                //     icon: icon_nearby,
                //     path: '/packageD/pages/nearby/index'
                // },
                // [
                //     {
                //         name: '应用',
                //         icon: icon_app,
                //         path: ''
                //     }
                // ]
            ],
    },
    {
        groupName: '商户服务',
        items: [
            // {
            //     name: '卖手列表',
            //     icon: icon_quanzi,
            //     path: '/packageD/pages/seller/index'
            // },
            {
                name: '转发金',
                icon: 'icon-fblh',
                path: '/packageD/pages/forward/setBonus'
            },
            {
                name: '找需求',
                icon: 'icon-zhaoxuqiu',
                path: '/packageD/pages/demand/index',
                width: '36rpx'
            },
            {
                name: '一码人脉',
                icon: 'icon-renmai1',
                path: '/packageD/pages/sites/index'
            }
        ],
    },
    {
        groupName: '用户服务',
        items: [
            {
                name: '转发赚钱',
                icon: 'icon-jiangli1',
                path: '/packageD/pages/forward/index'
            },
            {
                name: '区域服务',
                icon: 'icon-quyufuwuzhongxin',
                path: '/packageD/pages/regionalService/apply'
            },
            // {
            //     name: '成为卖手',
            //     icon: icon_quanzi,
            //     path: '/packageD/pages/seller/guide'
            // },
            {
                name: '找服务',
                icon: 'icon-fuwu',
                path: '/packageD/pages/service/index'
            }
        ],
    }
])
const handleClick = (item: { path: string; handler?: Function; }) => {
    if (item.path) {
        route({
            url: item.path,
        })
    } else if (item.handler) {
        item.handler()
    }
}


onLoad(async () => {
    const { data, code } = await productApi.getShopList({
        nopaging: true,
        shopType: 3,
        userId: userInfo.value.id,
        status: 20,
        otherColumns: 'vipReserve'
    })
    if (code == 200) {
        shopList.value = data.records
        if(  shopList.value.length >0 ) {

            features.value[2].items.unshift({
                name: '用户管理',
                icon: 'icon-yonghuguanli-2',
                path: '/packageD/pages/userManage/index',
                width: '48rpx'
            })
        }
    } else {
        shopList.value = []
    }

})


</script>

<style scoped lang="scss">
.discover {
    height: 100%;
    overflow-y: scroll;

    .cellBox {
        margin-bottom: 20rpx;

        .gname {
            font-size: 28rpx;
            margin-top: 30rpx;
            margin-bottom: 20rpx;
            padding-left: 20rpx;
        }

        .cellItem {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 24rpx 20rpx;
            border-bottom: 1px solid #F0F0F0;
            background: #fff;

            .cell-left {
                display: flex;
                align-items: center;

                .icon {
                    margin-right: 20rpx;
                    display: flex;
                    align-items: center;
                }

                .con {
                    flex: 1;

                    .name {
                        font-size: 28rpx;
                        color: #000;

                        &.avatar {
                            font-size: 32rpx;
                            font-weight: 600;
                            margin-bottom: 20rpx;
                        }
                    }

                    .other {
                        font-size: 24rpx;
                        color: #999;
                    }
                }
            }

            .cell-right {
                display: flex;
                align-items: center;
            }
        }
    }
}
</style>